package com.all.play.mymvpthree;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import com.all.play.mymvpthree.adapter.MyAdapter;
import com.all.play.mymvpthree.bean.InfoBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import okhttp3.Call;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        initData();
    }



    private void initView() {
        listView = (ListView) findViewById(R.id.lv);

    }

    private void initData() {


        OkHttpUtils
                .post()
                .url("http://www.kuaidi100.com/query?type=yuantong&postid=11111111111")
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {

                        Gson gson = new Gson();

                        InfoBean infoBean = gson.fromJson(response, InfoBean.class);
                        if(infoBean!=null){
                            List<InfoBean.DataBean> data = infoBean.getData();
                            myAdapter = new MyAdapter(MainActivity.this, data);

                            listView.setAdapter(myAdapter);
                        }



                    }
                });
    }
}
